/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.b.b;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import com.qihoo.gamecenter.sdk.suspend.b.b;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.net.ssl.SSLHandshakeException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.util.ByteArrayBuffer;
import org.json.JSONException;
import org.json.JSONObject;

public class g implements f {
    private static f a;
    private static Lock b = new ReentrantLock();
    private final c c = new c();

    public static f a() {
        if (a == null)
            try {
                b.lock();
                if (a != null)
                    break label33;
                label33: a = new g();
            } finally {
                b.unlock();
            }
        return a;
    }

    private String a(int paramInt, String paramString) {
        return "{\"errno\":" + paramInt + ",\"errmsg\":\"" + paramString + "\"}";
    }

    public String a(Context paramContext, List paramList, String paramString1, String paramString2) {
        HttpResponse localHttpResponse = b(paramContext, paramList, paramString1, paramString2);
        return a(localHttpResponse);
    }

    public String a(HttpResponse paramHttpResponse) {
        String str = null;
        InputStream localInputStream = null;
        if (paramHttpResponse != null)
            try {
                localInputStream = paramHttpResponse.getEntity().getContent();
                str = new String(a(localInputStream), "UTF-8");
            } catch (Exception localException) {
                b.a("HttpServerAgentImpl", localException);
            } finally {
                if (localInputStream != null)
                    try {
                        localInputStream.close();
                    } catch (IOException localIOException2) {
                        b.a("HttpServerAgentImpl", localIOException2);
                    }
            }
        return str;
    }

    public HttpResponse b(Context paramContext, List paramList, String paramString1, String paramString2) {
        try {
            HttpResponse localHttpResponse = this.c.a(paramContext, paramList, paramString1, paramString2);
            return localHttpResponse;
        } catch (SSLHandshakeException localSSLHandshakeException) {
            b.a("HttpServerAgentImpl", localSSLHandshakeException);
        } catch (IOException localIOException) {
            b.a("HttpServerAgentImpl", localIOException);
        } catch (TimeoutException localTimeoutException) {
            b.a("HttpServerAgentImpl", localTimeoutException);
        }
        return null;
    }

    public String a(Context paramContext, String paramString1, String paramString2) {
        String str = null;
        InputStream localInputStream = null;
        try {
            b.a("HttpServerAgentImpl", "doGetHttpResp url = " + paramString1);
            HttpResponse localHttpResponse = this.c.a(paramContext, paramString1, paramString2);
            if (localHttpResponse == null)
                break label112;
            int i = localHttpResponse.getStatusLine().getStatusCode();
            b.a("HttpServerAgentImpl", "doGetHttpResp st = " + i);
            localInputStream = localHttpResponse.getEntity().getContent();
            label112: str = new String(a(localInputStream), "UTF-8");
        } catch (SSLHandshakeException localSSLHandshakeException) {
            b.a("HttpServerAgentImpl", localSSLHandshakeException);
            str = a(-11, localSSLHandshakeException.getMessage());
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
            b.a("HttpServerAgentImpl", localUnsupportedEncodingException);
            str = a(-11, localUnsupportedEncodingException.getMessage());
        } catch (ClientProtocolException localClientProtocolException) {
            b.a("HttpServerAgentImpl", localClientProtocolException);
            str = a(-11, localClientProtocolException.getMessage());
        } catch (IOException localIOException1) {
            b.a("HttpServerAgentImpl", localIOException1);
            str = a(-11, localIOException1.getMessage());
        } catch (TimeoutException localTimeoutException) {
            b.a("HttpServerAgentImpl", localTimeoutException);
            str = a(-10, localTimeoutException.getMessage());
        } finally {
            if (localInputStream != null)
                try {
                    localInputStream.close();
                } catch (IOException localIOException7) {
                    b.a("HttpServerAgentImpl", localIOException7);
                }
        }
        a(str);
        return str;
    }

    public byte[] a(InputStream paramInputStream) {
        ByteArrayBuffer localByteArrayBuffer = new ByteArrayBuffer(0);
        byte[] arrayOfByte = new byte[1024];
        try {
            int i;
            while ((i = paramInputStream.read(arrayOfByte)) > 0)
                localByteArrayBuffer.append(arrayOfByte, 0, i);
        } catch (IOException localIOException) {
            b.a("HttpServerAgentImpl", localIOException);
        }
        return localByteArrayBuffer.toByteArray();
    }

    public String a(Context paramContext, String paramString1, String paramString2, String paramString3) {
        String str = a(paramContext, paramString1, paramString2);
        return str;
    }

    private void a(String paramString) {
        try {
            JSONObject localJSONObject = new JSONObject(paramString);
            if (localJSONObject == null)
                return;
            int i = localJSONObject.optInt("errno");
            if (4001 != i)
                return;
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {}
            });
        } catch (JSONException localJSONException) {
            b.a("HttpServerAgentImpl", "JudgeShowLogin is not parsable.");
        } catch (Exception localException) {}
    }
}